# -*- coding: utf-8 -*-
# @Time    : 2020/5/3 8:50
# @Author  : Jhin•W
# @Email   : 261229090@qq.com
# @File    : chengyuan.py
# @Software: PyCharm
#---------------------------------------------------

# class Foo():
#     def __init__(self, name, age):
#         self.name = name
#         #self.age = age
#         self.__age = age    #私有，外部无法直接方法
#
#     def show(self):
#         return self.__age
#
# obj = Foo('abc', 19)
# print(obj.name)
# #print(obj.__age)
# ret = obj.show()
# print(ret)

"""
class F:
    def __init__(self):
        self.ge = 123
        self.__gene = 123

class S(F):     # 继承
    def __init__(self, name):
        self.name = name
        self.__age = 18
        super(S, self).__init__()
    def show(self):
        print(self.name)
        print(self.__age)
        print(self.ge)
        print(self.__gene)

s = S('abc')
s.show()
"""

# class Foo:
#     def __init__(self):
#         print('init')
#
#     def __call__(self, *args, **kwargs):
#         print('call')
#
# obj = Foo()
# obj()
# Foo()()

"""
class Foo:
    def __init__(self):
        pass
    def __int__(self):
        return 1
    def __str__(self):
        return 'abc'
obj = Foo()
print(obj, type(obj))
# int，对象，自动执行对象的__init__方法，并将返回值赋值给int对象
r = int(obj)
print(r)
i = str(obj)
print(i)
"""

class Foo:
    def __init__(self, n, a):
        self.name = n
        self.age = a
    def __str__(self):
        return '%s - %s' %(self.name, self.age)

obj = Foo('abc', 18)
print(obj)  #print(str(obj))  obj中__str__，并获取其返回值